package client;

import contract.HelloWorldService;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TMultiplexedProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

/**
 * @Author: admin
 * @Description:
 * @Date: 2019/3/7 16:21
 */

public class ThriftClient {
    public static void main(String[] args) throws TException {
        //simple();
        mult();
    }

    public static void simple() throws TException {
        TTransport tTransport=new TSocket("192.168.10.66",9999);
        tTransport.open();
        TProtocol protocol=new TCompactProtocol(tTransport);
        HelloWorldService.Client client=new HelloWorldService.Client(protocol);

        System.out.println(client.sayHello("sjw"));
        tTransport.close();
    }

    public static void mult() throws TException {
        TTransport tTransport=new TSocket("192.168.10.66",9999);
        tTransport.open();
        TProtocol protocol=new TCompactProtocol(tTransport);
        HelloWorldService.Client client=new HelloWorldService.Client(new TMultiplexedProtocol(protocol,"hello"));

        System.out.println(client.sayHello("sjw"));
        tTransport.close();
    }
}
